//
//  CGFloat+Global.swift
//  DF_Student
//
//  Created by 刘盖 on 2023/12/9.
//  Copyright © 2023 DFJGED. All rights reserved.
//

import UIKit

public extension CGFloat {
    
    static var screen_width: CGFloat {
        get {
            return UIScreen.main.bounds.size.width
        }
    }

    static var screen_height: CGFloat {
        get {
            return UIScreen.main.bounds.size.height
        }
    }
  
    static var status_bar_height: CGFloat {
        get {
            return maximum(UIApplication.shared.statusBarFrame.size.height, 20)
        }
    }
    
    static var nav_bar_height: CGFloat {
        get {
            return UINavigationController().navigationBar.frame.size.height
        }
    }
    
    static var bottom_safe_height: CGFloat {
        get {
            return UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
        }
    }
    
    //iPhone设计比例基数 宽度375，  iPad设计比例基数 宽度800
    static var phone_ratio_base: CGFloat {
        get {
            return 375
        }
    }
    
    static var pad_ratio_base: CGFloat {
        get {
            return 800
        }
    }

    static var ratio_phone: CGFloat {
        get {
            return minimum(self.screen_width, self.screen_height)/self.phone_ratio_base
        }
    }
    
    static var ratio_pad: CGFloat {
        get {
            return minimum(self.screen_width, self.screen_height)/self.pad_ratio_base
        }
    }
    
    //比例，由于担心横屏情况下，宽度太宽，使得比例不协调，所以以375为基准，当前屏幕宽、高谁小取谁，来计算比例
    //这个值不会变，因为永远只取宽高中小的一方，不受横竖屏变化影响，也就是横屏的时候会取高度，竖屏会取宽度
    static var ratio: CGFloat {
        get {
            return self.ratio_phone
        }
    }
    
    static var ratio_x: CGFloat {
        get {
            return self.screen_width/375.0
        }
    }
    
    static var ratio_y: CGFloat {
        get {
            return self.screen_height/667.0
        }
    }
    
    //最小值为1的屏幕比例
    static var ratio_min_1: CGFloat {
        get {
            return maximum(self.ratio, 1)
        }
    }

    //计算比例后的距离
    static func ratioSize(_ size: CGFloat) -> CGFloat {
        return self.ratio * size
    }
    
    static var tab_bar_height: CGFloat {
        get {
            return Bool.isIPad ? 70 : (Bool.isIPhoneX ? 83 : 49)
        }
    }
    
    static var standard_top_height: CGFloat {
        get {
            return self.status_bar_height+self.nav_bar_height
        }
    }
    
    static var adapter_nav_height: CGFloat {
        get {
            return minimum(82, Bool.isIPad ? (82*self.ratio_pad) : self.nav_bar_height)
        }
    }
    
    static var adapter_tool_height: CGFloat {
        get {
            return self.adapter_nav_height
        }
    }
    
    static var adapter_top_height: CGFloat {
        get {
            return self.status_bar_height+self.adapter_nav_height
        }
    }
    
    static var adapter_bottom_height: CGFloat {
        get {
            return self.bottom_safe_height+self.adapter_tool_height
        }
    }
    
    // 这个通常用来作为顶部、底部、中间等bar的比例计算
    static var ratio_adapter_bar: CGFloat {
        get {
            return self.adapter_nav_height/44.0
        }
    }

    
}
